//
//  CCYMeCollorViewTableViewCell.m
//  模拟-百思不得姐
//
//  Created by 程春玉 on 16/8/5.
//  Copyright © 2016年 chunyu. All rights reserved.
//

#import "CCYMeCollorViewTableViewCell.h"
#import "CCYMeActivityModel.h"
#import <UIButton+WebCache.h>

#define viewHeight self.contentView.width / 5 + 20

@interface CCYMeCollorViewTableViewCell()

@end


@implementation CCYMeCollorViewTableViewCell

- (void)setMessageWithArray:(NSArray *)arr
{
    for (int i = 0; i < arr.count; i++) {
        CCYMeActivityModel *model = arr[i];
        [self.contentView addSubview:[self createItemWithPoint:i < 5 ? CGPointMake(i * (self.contentView.width / 5), 0) : CGPointMake((i - 5) * (self.contentView.width / 5), viewHeight) imgStr:model.icon labelName:model.name]];
    }
}

- (UIView *)createItemWithPoint:(CGPoint)point imgStr:(NSString *)imgStr labelName:(NSString *)labelName
{
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(point.x, point.y, self.contentView.width / 5, viewHeight)];
    backView.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn.frame = CGRectMake(0, 10, self.contentView.width / 5 - 10, self.contentView.width / 5 - 10);
    [btn sd_setImageWithURL:[NSURL URLWithString:imgStr] forState:(UIControlStateNormal)];
    btn.layer.cornerRadius = btn.width / 2;
    btn.clipsToBounds = YES;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:(UIControlEventTouchUpInside)];
    [backView addSubview:btn];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, btn.height + 10, backView.width - 10, 15)];
    label.text = labelName;
    label.font = [UIFont systemFontOfSize:12];
    label.textAlignment = NSTextAlignmentCenter;
    [backView addSubview:label];
    return backView;
}

- (void)btnClick:(UIButton *)btn
{
    XMGLog(@"2222");
}


- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}





@end
